package com.wangsd.common.utils;

import com.alipay.api.AlipayClient;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient;

public class AliClientUtil {
    public static String ALIPAY_DEFAULT_URL = "https://openapi.alipay.com/gateway.do";
    public static String ALIPAY_FORMART = "json";
    public static String ALIPAY_SIGN_TYPE = "RSA2";
    public static String ALIPAY_CHARSET = "UTF-8";


    public static CertAlipayRequest initCertAlipayRequest(
            String appId, String AliPrivateKey, String appCertPublicKeyPath,
            String alipayCertPublicKeyPath,String alipayRootCertPath) {

        CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
        certAlipayRequest.setServerUrl(ALIPAY_DEFAULT_URL);
        certAlipayRequest.setAppId(appId);
        certAlipayRequest.setPrivateKey(AliPrivateKey);
        certAlipayRequest.setFormat(ALIPAY_FORMART);
        certAlipayRequest.setCharset(ALIPAY_CHARSET);
        certAlipayRequest.setSignType(ALIPAY_SIGN_TYPE);
        certAlipayRequest.setCertPath(appCertPublicKeyPath);
        certAlipayRequest.setAlipayPublicCertPath(alipayCertPublicKeyPath);
        certAlipayRequest.setRootCertPath(alipayRootCertPath);
        return certAlipayRequest;
    }


    public static AlipayClient initAlipayRequest(
            String appId, String aliPrivateKey, String aliPublicKey ) {
        //初始化支付宝SDK客户端
        AlipayClient client = new DefaultAlipayClient(ALIPAY_DEFAULT_URL,appId,
                aliPrivateKey,ALIPAY_FORMART,ALIPAY_CHARSET,aliPublicKey,ALIPAY_SIGN_TYPE
        );
        return client;
    }

}
